#!/bin/bash
#
createEpsP()
{
title="blastFoam_multicomponent_validation_p"
    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "$title.eps"
    set xlabel "X-Position (m)"
    set ylabel "Pressure [Pa]"
#     set grid
    set key right top
    set size 2,2
    set autoscale
    set xrange [0:1]
    set yrange [0:10]
    plot    "$1" using 1:2 title 'Gas - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'red',\
            "$2" using 1:2 title 'Particles - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'blue',\
            "$3" using 1:(\$2/101298) title 'Gas - blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'red', \
            "$3" using 1:(\$3*50000/101298) title 'Particles blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'blue'
EOF
}

createEpsU()
{
title="blastFoam_multicomponent_validation_U"
    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "$title.eps"
    set xlabel "X-Position (m)"
    set ylabel "X-Velocity [m/s]"
#     set grid
    set key right top
    set size 2,2
    set autoscale
    set xrange [0:1]
    set yrange [0:500]
    plot    "$1" using 1:2 title 'Gas - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'red',\
            "$2" using 1:2 title 'Particles - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'blue',\
            "$3" using 1:2 title 'Gas - blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'red', \
            "$3" using 1:5 title 'Particles blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'blue'
EOF
}

createEpsT()
{
title="blastFoam_multicomponent_validation_T"
    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "$title.eps"
    set xlabel "X-Position (m)"
    set ylabel "Temperature [K]"
#     set grid
    set key right top
    set size 2,2
    set autoscale
    set xrange [0:1]
    set yrange [200:600]
    plot    "$1" using 1:2 title 'Gas - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'red',\
            "$2" using 1:2 title 'Particles - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'blue',\
            "$3" using 1:4 title 'Gas - blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'red', \
            "$3" using 1:5 title 'Particles - blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'blue'
EOF
}

createEpsRho()
{
title="blastFoam_multicomponent_validation_rho"
    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "$title.eps"
    set xlabel "X-Position (m)"
    set ylabel "Phasic density [kg/m^3]"
#     set grid
    set key right top
    set size 2,2
    set autoscale
    set xrange [0:1]
    set yrange [0:5]
    plot    "$1" using 1:2 title 'Gas - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'red',\
            "$2" using 1:2 title 'Particles - Houim Oran (2016)'\
                with points linewidth 8 linecolor rgb 'blue',\
            "$3" using 1:(\$7*(1-\$6)) title 'Gas - blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'red', \
            "$3" using 1:(2500*\$6) title ' Particles- blastFoam'\
                with lines lt 1 linewidth 2 linecolor rgb 'blue'
EOF
}

# test if gnuplot exists on the system
if ! which gnuplot > /dev/null 2>&1
then
    echo "gnuplot not found - skipping graph creation" >&2
    exit 1
fi

# paths to data
VALIDATIONDATAROOT=./validationData

pgVal="$VALIDATIONDATAROOT/p_g_10.csv"
psVal="$VALIDATIONDATAROOT/p_s_10.csv"
UgVal="$VALIDATIONDATAROOT/U_g_10.csv"
UsVal="$VALIDATIONDATAROOT/U_s_10.csv"
TgVal="$VALIDATIONDATAROOT/T_g_10.csv"
TsVal="$VALIDATIONDATAROOT/T_s_10.csv"
rhogVal="$VALIDATIONDATAROOT/rho_g_10.csv"
rhosVal="$VALIDATIONDATAROOT/rho_s_10.csv"
blastFOAMs="../postProcessing/sampleDict/*/Centerline_p*"
blastFOAMv="../postProcessing/sampleDict/*/Centerline_U*"

createEpsP $pgVal $psVal $blastFOAMs
createEpsU $UgVal $UsVal $blastFOAMv
createEpsT $TgVal $TsVal $blastFOAMs
createEpsRho $rhogVal $rhosVal $blastFOAMs

echo Done
